package com.toKnow.controller;

import com.toKnow.model.vo.CommonResult;
import com.toKnow.service.UtilService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * 获取一些工具表，如学历、学校、标签、类型等
 */
@Controller
@RequestMapping(value = "/api/util")
public class UtilController {
    @Resource
    private UtilService utilService;

    /**
     * 获取学历列表
     * /util/education/names
     * GET{}{commonResult}
     */
    @RequestMapping(value = "/education/names")
    @ResponseBody
    public CommonResult getEducation(){
        CommonResult cm = new CommonResult();
        List<String> name = utilService.getEducation();
        boolean success = name.size() > 0;
        cm.setSuccess(success);
        cm.setMessage(success ? "" : "获取学历列表失败");
        cm.setObject(name); // list::name: String
        return cm;
    }

    /**
     * 获取学历列表
     * /util/education/names
     * GET{}{commonResult}
     */
    @RequestMapping(value = "/university/names")
    @ResponseBody
    public CommonResult getUniversity(){
        CommonResult cm = new CommonResult();
        List<String> name = utilService.getUniversity();
        boolean success = name.size() > 0;
        cm.setSuccess(success);
        cm.setMessage(success ? "" : "获取大学列表失败");
        cm.setObject(name); // list::name: String
        return cm;
    }

    /**
     * 获取标签列表
     * /util/tag/names
     * GET{}{commonResult}
     */
    @RequestMapping(value = "/tag/names")
    @ResponseBody
    public CommonResult getTag(){
        CommonResult cm = new CommonResult();
        List<String> name = utilService.getTag();
        boolean success = name.size() > 0;
        cm.setSuccess(success);
        cm.setMessage(success ? "" : "获取标签列表失败");
        cm.setObject(name); // list::name: String
        return cm;
    }

    /**
     * 获取类型列表
     * /util/type/names
     * GET{}{commonResult}
     */
    @RequestMapping(value = "/type/names")
    @ResponseBody
    public CommonResult getType(){
        CommonResult cm = new CommonResult();
        List<String> name = utilService.getType();
        boolean success = name.size() > 0;
        cm.setSuccess(success);
        cm.setMessage(success ? "" : "获取类型列表失败");
        cm.setObject(name); // list::name: String
        return cm;
    }
}
